using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using User.Domain.Entities;
using User.Domain.Repositories;

namespace User.Infrastructure.Repositories
{
    
    public class UserRepository : IUserRepository
    {
        private readonly UserDbContext _context;

        public UserRepository(UserDbContext context)
        {
            _context = context;
        }
        public async Task AddAsync(UserProfile entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            await _context.UserProfiles.AddAsync(entity);
           
        }

        public async Task DeleteAsync(Guid id)
        {
            var user = await _context.UserProfiles.FindAsync(id);
            if (user == null)
            {
                throw new KeyNotFoundException($"User with ID {id} not found.");
            }
            _context.UserProfiles.Remove(user);
        }

        public Task<IEnumerable<UserProfile>> GetAllAsync()
        {
            throw new NotImplementedException();
        }

        public Task<IEnumerable<UserProfile>> GetAllAsync(string? filter = null, CancellationToken cancellationToken = default)
        {
            throw new NotImplementedException();
        }

        public Task<UserProfile> GetByIdAsync(Guid id)
        {
            throw new NotImplementedException();
        }

        public Task<UserProfile> GetUserByEmailAsync(string email)
        {
            throw new NotImplementedException();
        }

        public Task<IEnumerable<UserProfile>> GetUsersByRoleAsync(string roleName)
        {
            throw new NotImplementedException();
        }

        public Task<IEnumerable<UserProfile>> GetUsersByStatusAsync(string status)
        {
            throw new NotImplementedException();
        }

        public async Task UpdateAsync(UserProfile entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            var existingUser = await _context.UserProfiles.FindAsync(entity.Id);
            if (existingUser == null)
            {
                throw new KeyNotFoundException($"User with ID {entity.Id} not found.");
            }
            _context.Entry(existingUser).CurrentValues.SetValues(entity);
        }
    }
}